package filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by ARCSINX on 4/27/2017.
 */
@WebFilter(filterName = "CharacterEncodingFilter",urlPatterns = "/*",servletNames = "HelloServlet")
public class CharacterEncodingFilter implements Filter
{
    public void destroy()
    {
    }

    /**
     * Call before navigate to a Servlet or JSP
     * @param req
     * @param resp
     * @param chain
     * @throws ServletException
     * @throws IOException
     */
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException
    {
        resp.setCharacterEncoding("utf-8");

        PrintWriter writer = resp.getWriter();


        chain.doFilter(req, resp);
    }

    /**
     * Get parameters of filters
     * @param config
     * @throws ServletException
     */
    public void init(FilterConfig config) throws ServletException
    {

    }

}
